{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from k3d.helpers import download\n",
    "from pyunpack import Archive\n",
    "\n",
    "filename = download('http://www.semantic3d.net/data/point-clouds/testing1/stgallencathedral_station1_intensity_rgb.7z')\n",
    "Archive(filename).extractall('./')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "import numpy as np \n",
    "\n",
    "data = None\n",
    "\n",
    "with open(filename.replace('.7z', '.txt'), mode='r') as csv_file:\n",
    "    csv_reader = csv.reader(csv_file, delimiter=' ')    \n",
    "    data = np.array(list(csv_reader), dtype=np.float32)\n",
    "\n",
    "# compute color in hex format\n",
    "data[:, 4] = np.sum(data[:, 4:7].astype(np.uint32) * np.array([1, 256, 256 ** 2]), axis=1)    \n",
    "data = data[:, 0:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import time\n",
    "import json\n",
    "import k3d\n",
    "import ipywidgets as widgets\n",
    "\n",
    "plot = k3d.plot()\n",
    "plot.display()\n",
    "debug_info = widgets.HTML()\n",
    "display(debug_info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "obj = k3d.points(data[::2, 0:3], data[::2, 4].astype(np.uint32), point_size=0.05, shader=\"flat\") \n",
    "plot += obj"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot.camera = [5.251483149143791,\n",
    " -7.92683507646606,\n",
    " 3.144285796928443,\n",
    " -2.470283607444292,\n",
    " 3.6558150584160503,\n",
    " 2.3721091212696286,\n",
    " 0,\n",
    " 0,\n",
    " 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot.mode = 'callback'\n",
    "\n",
    "import json \n",
    "\n",
    "g = None\n",
    "def foo(params):\n",
    "    global g, debug_info\n",
    "    \n",
    "    g = params\n",
    "    debug_info.value = '<pre>' + json.dumps(params, indent=4) + \"</pre>\"\n",
    "\n",
    "obj.click_callback = foo\n",
    "obj.hover_callback = foo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
